<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="8">
                <el-card shadow="hover" class="mgb20" style="height:180px;">
                    <div class="user-info">
                        <img :src="imgsrc" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">{{name}}</div>
                            <div>{{roleNms}}</div>
                        </div>
                    </div>
                    <!--<div class="user-info-list">
                        上次登录时间：
                        <span>{{lastLoginTm}}</span>
                    </div>
                    <div class="user-info-list">
                        上次登录地点：
                        <span>东莞</span>
                    </div>-->
                </el-card>
                <el-card shadow="hover" style="height:324px;">
                    <div slot="header" class="clearfix">
                        <span>设备在线统计</span>
                    </div>
                    <!--Vue
                    <el-progress :percentage="71.3" color="#42b983"></el-progress>
                    JavaScript
                    <el-progress :percentage="24.1" color="#f1e05a"></el-progress>
                    CSS
                    <el-progress :percentage="13.7"></el-progress>
                    HTML
                    <el-progress :percentage="5.9" color="#f56c6c"></el-progress>-->
                    <div ref="myChart" style="height: 200px"></div>
                </el-card>
            </el-col>
            <el-col :span="16">
                <el-row :gutter="20" class="mgb20">
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-1">
                                <i class="el-icon-office-building grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">1234</div>
                                    <div>接入医院</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-2">
                                <i class="el-icon-set-up grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">321</div>
                                    <div>接入设备</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                    <el-col :span="8">
                        <el-card shadow="hover" :body-style="{padding: '0px'}">
                            <div class="grid-content grid-con-3">
                                <i class="el-icon-s-opportunity grid-con-icon"></i>
                                <div class="grid-cont-right">
                                    <div class="grid-num">5000</div>
                                    <div>在线设备</div>
                                </div>
                            </div>
                        </el-card>
                    </el-col>
                </el-row>
                <el-card shadow="hover" style="height:403px;">
                    <div slot="header" class="clearfix">
                        <span>通知公告</span>
                        <!--<el-button style="float: right; padding: 3px 0" type="text">添加</el-button>-->
                    </div>
                    <el-table :show-header="false" :data="todoList" style="width:100%;font-size: 14px;">
                        <el-table-column prop="title" label="" align="left"></el-table-column>
                        <el-table-column prop="date" label="" align="right" width="100"></el-table-column>
                        <!--<el-table-column>
                            <template slot-scope="scope">
                                <div class="todo-item">{{scope.row.title}}</div>
                            </template>
                        </el-table-column>
                        <el-table-column width="100">
                            <template slot-scope="scope">
                                <span>{{scope.row.date}}</span>
                            </template>
                        </el-table-column>-->
                    </el-table>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="hover">
                    <schart ref="line" class="schart" canvasId="line" :options="options2"></schart>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import Schart from 'vue-schart';
    import bus from '../../common/bus';
    import { doIndex } from '../../../api/index';
    import vueSeamlessScroll from "vue-seamless-scroll";
    export default {
        name: 'dashboard',
        data() {
            return {
                name: localStorage.getItem('ms_userAcct'),
                roleIds: localStorage.getItem('ms_roleIds'),
                lastLoginTm: localStorage.getItem('ms_lastLoginTm'),
                roleNms: localStorage.getItem('ms_roleNms'),
                legendData: null,
                selected: null,
                seriesData: null,
                todoList: [
                    {
                        title: '希迪克（中国）和比利时希迪克官方网站正式上线',
                        status: false,
                        date: '2020-11-04'
                    },
                    {
                        title: '上饶市第五人民医院院长吴山茅，康复科主任马亨一行莅临希迪克参观考察',
                        status: false,
                        date: '2020-11-13'
                    },
                    {
                        title: '希迪克与您相约第三届中国国际进口博览会',
                        status: false,
                        date: '2020-11-06'
                    },
                    {
                        title: '大家期待已久的“希迪克”公众号已经上线啦',
                        status: false,
                        date: '2020-10-19'
                    },
                    {
                        title: '党建引领活力”两新“---汇博医疗党支部揭牌仪式',
                        status: true,
                        date: '2020-09-30'
                    }
                ],
                options: {
                    colorList:['rgba(4,57,102,0.5)','rgba(98,195,208,0.5)','rgba(143,255,143,0.5)'],
                    type: 'bar',
                    title: {
                        text: '最近一周各训练类型患者数量图'
                    },
                    xRorate: 25,
                    labels: ['周一', '周二', '周三', '周四', '周五'],
                    datasets: [
                        {
                            label: '主动训练',
                            data: [234, 278, 270, 190, 230]
                        },
                        {
                            label: '被动训练',
                            data: [164, 178, 190, 135, 160]
                        },
                        {
                            label: '电刺激',
                            data: [144, 198, 150, 235, 120]
                        }
                    ]
                },
                options2: {
                    colorList:['rgba(4,57,102,0.5)','rgba(98,195,208,0.5)','rgba(143,255,143,0.5)'],
                    type: 'line',
                    title: {
                        text: '最近几个月各训练类型患者数量统计图'
                    },
                    labels: ['6月', '7月', '8月', '9月', '10月'],
                    datasets: [
                        {
                            label: '主动训练',
                            data: [234, 278, 270, 190, 230]
                        },
                        {
                            label: '被动训练',
                            data: [164, 178, 150, 135, 160]
                        },
                        {
                            label: '电刺激',
                            data: [74, 118, 200, 235, 90]
                        }
                    ]
                }
            };
        },
        components: {
            Schart,
            vueSeamlessScroll
        },
        computed: {
            imgsrc() {
                let imgtp = localStorage.getItem('ms_imgTp');
                let imgdata = localStorage.getItem('ms_imgData');
                if (imgtp != 'null' && imgdata != 'null' && imgtp != "" && imgdata != ""){
                    return 'data:image/'+ imgtp +';base64,' + imgdata;
                } else {
                    return require("@/assets/img/user_img.gif");
                }
            }
        },
        mounted() {
            doIndex().then(res => {
                if (res.success == true){
                    this.legendData = res.data.legendData;
                    this.selected = res.data.selected;
                    this.seriesData = res.data.seriesData;
                    this.myNewEcharts();
                }
            });
        },
        methods: {
            changeDate() {
                const now = new Date().getTime();
                this.data.forEach((item, index) => {
                    const date = new Date(now - (6 - index) * 86400000);
                    item.name = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
                });
            },
            myNewEcharts(){
                /*let data = {
                    legendData:["站立架", "上肢", "下肢", "磁刺激"],
                    selected: {
                        "站立架":true,
                        "上肢":true,
                        "下肢":true,
                        "磁刺激":false
                    },
                    seriesData:[
                        {
                            name:"站立架",
                            value: 300
                        },
                        {
                            name:"上肢",
                            value: 200
                        },
                        {
                            name:"下肢",
                            value: 200
                        },
                        {
                            name:"磁刺激",
                            value: 600
                        },
                    ]
                };*/
                let option = {
                    title: {
                        text: '',
                        subtext: '',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        type: 'scroll',
                        orient: 'vertical',
                        right: 5,
                        top: 5,
                        bottom: 5,
                        data: this.legendData,
                        selected: this.selected
                    },
                    series: [
                        {
                            name: '设备名',
                            type: 'pie',
                            radius: '70%', //调节饼图大小
                            center: ['40%', '50%'], //调节饼图左右位置
                            data: this.seriesData,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                let myChart = this.$echarts.init(this.$refs.myChart);
                myChart.showLoading();
                myChart.hideLoading();
                myChart.setOption(option);
            }
        }
    };
</script>


<style scoped>
    .el-row {
        margin-bottom: 20px;
    }

    .grid-content {
        display: flex;
        align-items: center;
        height: 100px;
    }

    .grid-cont-right {
        flex: 1;
        text-align: center;
        font-size: 14px;
        color: #999;
    }

    .grid-num {
        font-size: 30px;
        font-weight: bold;
    }

    .grid-con-icon {
        font-size: 50px;
        width: 100px;
        height: 100px;
        text-align: center;
        line-height: 100px;
        color: #fff;
    }

    .grid-con-1 .grid-con-icon {
        background: rgb(81, 182, 204);
    }

    .grid-con-1 .grid-num {
        color: rgb(45, 140, 240);
    }

    .grid-con-2 .grid-con-icon {
        background: rgb(159, 207, 132);
    }

    .grid-con-2 .grid-num {
        color: rgb(45, 140, 240);
    }

    .grid-con-3 .grid-con-icon {
        background: rgb(234, 151, 72);
    }

    .grid-con-3 .grid-num {
        color: rgb(145, 242, 234);
    }

    .user-info {
        display: flex;
        align-items: center;
        padding-bottom: 20px;
        border-bottom: 2px solid #ccc;
        margin-bottom: 20px;
    }

    .user-avator {
        width: 120px;
        height: 120px;
        border-radius: 50%;
    }

    .user-info-cont {
        padding-left: 50px;
        flex: 1;
        font-size: 14px;
        color: #999;
    }

    .user-info-cont div:first-child {
        font-size: 30px;
        color: #222;
    }

    .user-info-list {
        font-size: 14px;
        color: #999;
        line-height: 25px;
    }

    .user-info-list span {
        margin-left: 70px;
    }

    .mgb20 {
        margin-bottom: 20px;
    }

    .todo-item {
        font-size: 14px;
    }

    .todo-item-del {
        text-decoration: line-through;
        color: #999;
    }

    .schart {
        width: 100%;
        height: 300px;
    }

</style>
